package top.itlir.edc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.itlir.edc.dao.CourierRepository;
import top.itlir.edc.dao.FixedAreaRepository;
import top.itlir.edc.dao.TakeTimeRepository;
import top.itlir.edc.domain.Courier;
import top.itlir.edc.domain.FixedArea;
import top.itlir.edc.domain.TakeTime;
import top.itlir.edc.service.FixedAreaService;

@Service
@Transactional
public class FixedAreaServiceImpl implements FixedAreaService {
	
	@Autowired
	private FixedAreaRepository fixedAreaRepository;
	@Autowired
	private CourierRepository courierRepository;
	
	private TakeTimeRepository takeTimeRepository;

	@Override
	public void save(FixedArea model) {
		fixedAreaRepository.save(model);
	}

	@Override
	public Page<FixedArea> findAll(Pageable pageable) {
		return fixedAreaRepository.findAll(pageable);
	}

	@Override
	public Page<FixedArea> findAll(Specification spec, Pageable pageable) {
		return findAll(spec, pageable);
	}

	@Override
	public void associationCourierToFixedArea(String id, Integer courierId,
			Integer takeTimeId) {
		
		FixedArea fixedArea = fixedAreaRepository.findOne(id);
		Courier courier = courierRepository.findOne(courierId);
		TakeTime takeTime = takeTimeRepository.findOne(takeTimeId);
		fixedArea.getCouriers().add(courier);
		courier.setTakeTime(takeTime);
	}




	
}
